package com.intellij.ide.license.idea;

import com.intellij.ide.license.impl.GeneralLicenseValidator;
import com.intellij.ide.license.impl.LicenseException;
import com.intellij.ide.license.impl.VersionNotMatchLicenseException;
import com.intellij.licensecommon.data.LicenseData;
import com.intellij.licensecommon.data.h;
import com.intellij.openapi.application.impl.ApplicationInfoImpl;

import java.util.Date;

public class IdeaLicenseValidator extends GeneralLicenseValidator {
    public static final int CURRENT_MAJOR_VERSION = 13;
    static final String VERSION = String.valueOf(CURRENT_MAJOR_VERSION);
    static final boolean d = true;

    public IdeaLicenseValidator() {
        super(1);
    }

    protected void checkUpgrade(LicenseData licenseData) throws LicenseException {
        if ((licenseData instanceof h)) {
            Date date = ((h) licenseData).getUpgradeDueDate();
            Date buildDate = ApplicationInfoImpl.getShadowInstance().getMajorReleaseBuildDate().getTime();
            if (buildDate.getTime() > date.getTime()) {
                throw new VersionNotMatchLicenseException();
            }
        } else if (CURRENT_MAJOR_VERSION > licenseData.getMajorVersion()) {
            throw new VersionNotMatchLicenseException();
        }
    }

    public int getCurrentMajorVersion() {
        return CURRENT_MAJOR_VERSION;
    }
}
